package com.ittx.dzt.meione.service;

import cn.hutool.core.map.MapUtil;
import com.ittx.dzt.edi.dto.PlatformApiParamDTO;
import com.ittx.dzt.meione.handler.AbstractBaseMeioneApiHandler;
import com.ittx.dzt.sys.response.Result;
import io.vavr.collection.List;
import lombok.extern.slf4j.Slf4j;
import open.constant.PlatformApiConstant;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 获取快递公司列表
 * <p>
 * cy.carrierPlatform.download
 * /erp/un/logistics/list 查询物流公司信息
 * </p>
 *
 * @author wl_code@163.com
 * @version 1.0
 * @date 2025/8/29
 */
@Slf4j
@Service
public class MeioneCarrierService extends AbstractBaseMeioneApiHandler<String> {

	@Override
	public String getMeioneMethod() {
		return "/erp/un/logistics/list";
	}

	@Override
	public String getLocalApiMethod() {
		return PlatformApiConstant.InboundInterface.CARRIER_PLATFORM_DOWNLOAD;
	}

	@Override
	public Result doProcess(PlatformApiParamDTO platformApiParamDTO, String s) {
		Result result = this.executeApi(platformApiParamDTO.getStoreConfig(), new HashMap<>(), platformApiParamDTO.getRequestId());
		if (!result.isSuccess()) {
			return result;
		}
		Map<String, Object> resultMap = (Map<String, Object>) result.getData();
		// List<Map<String, Object>> dataMap = (List<Map<String, Object>>) resultMap.get(DATA_FIELD);
		List listData = MapUtil.get(resultMap, "data", List.class);
		listData.forEach(data -> {
			this.sendRequestToPlatform(platformApiParamDTO, data, true);
		});
		return Result.success("共{}条,承运商信息", listData.size());
	}


}
